<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Data Driven Substructure: dataset.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Data Driven Substructure
   
   </div>
   <div id="projectbrief">A library for carrying out Multivariate Kernel Smoothing--designed to be fast and flexible for large data processing.</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">dataset.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef __DATASET__</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define __DATASET__</span>
<a name="l00003"></a>00003 <span class="preprocessor"></span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;covariance.h&quot;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &quot;tensor.h&quot;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &quot;pdf.h&quot;</span>
<a name="l00007"></a>00007 <span class="preprocessor">#include &quot;mtrand.h&quot;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;time.h&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;valarray&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00011"></a>00011 
<a name="l00020"></a><a class="code" href="classDataSet.html">00020</a> <span class="keyword">class </span><a class="code" href="classDataSet.html" title="a class to store multi-dimensional data">DataSet</a>{
<a name="l00021"></a>00021  <span class="keyword">public</span>:
<a name="l00022"></a>00022   <a class="code" href="classDataSet.html#a2a0c14de0e419a25801ce1d443ed20ba">DataSet</a>(<span class="keyword">const</span> valarray&lt;double&gt;&amp; <a class="code" href="classDataSet.html#a6f3d9efb73b7351d519cc58e6f889695" title="vector to store min values">min</a>, <span class="keyword">const</span> valarray&lt;double&gt;&amp; <a class="code" href="classDataSet.html#ad1091c9131411b8e99a1f2a52faf85be" title="vector to store max values">max</a>,
<a name="l00023"></a>00023           <span class="keyword">const</span> valarray&lt;double&gt;&amp; <a class="code" href="classDataSet.html#adfab405eda8e41df01199ee4c87d72a2" title="vector to store precision of variables">precision</a>);
<a name="l00027"></a>00027 
<a name="l00028"></a>00028   <a class="code" href="classDataSet.html#a2a0c14de0e419a25801ce1d443ed20ba">DataSet</a>(<span class="keywordtype">int</span> nvar, <span class="keywordtype">double</span>* min, <span class="keywordtype">double</span>* max, <span class="keywordtype">double</span>* precision_=NULL);
<a name="l00032"></a>00032 
<a name="l00033"></a><a class="code" href="classDataSet.html#a021cb974190e69518e340c2b501254d5">00033</a>   <span class="keywordtype">int</span> <a class="code" href="classDataSet.html#a021cb974190e69518e340c2b501254d5" title="return rank of the dataset">Rank</a>()<span class="keyword"> const</span>
<a name="l00034"></a>00034 <span class="keyword">  </span>{
<a name="l00035"></a>00035     <span class="keywordflow">return</span> <a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>;
<a name="l00036"></a>00036   }
<a name="l00038"></a>00038 
<a name="l00039"></a>00039   <span class="keyword">inline</span> valarray&lt;int&gt; <a class="code" href="classDataSet.html#a7261bb29701a071f76349854d1f39cb0">GetBin</a>(<span class="keyword">const</span> valarray&lt;double&gt;&amp; ntuple) <span class="keyword">const</span>;
<a name="l00042"></a>00042 
<a name="l00043"></a>00043   <span class="keywordtype">void</span> <a class="code" href="classDataSet.html#ad0c1c04d4bdd1a33a4ebac4010151847" title="fill dataset by a data sample">Fill</a>(<span class="keyword">const</span> valarray&lt;double&gt;&amp; ntuple, <span class="keywordtype">double</span> weight=1.0);
<a name="l00045"></a>00045 
<a name="l00046"></a>00046   <a class="code" href="classPDF.html" title="PDF functions.">PDF</a> <a class="code" href="classDataSet.html#a90c5673e76a3b700effd4bdbceeb1fbe" title="OLD core code to generate a PDF based on multivariate Kernel Smoothing.">ComputePDF_DirectSmoothing</a>(<span class="keywordtype">bool</span> timer_mode=<span class="keyword">false</span>);
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   <a class="code" href="classPDF.html" title="PDF functions.">PDF</a> <a class="code" href="classDataSet.html#a5cd26da77fe5563bdf4dca753c704720">ComputePDF</a>(<span class="keywordtype">bool</span> timer_mode=<span class="keyword">false</span>);
<a name="l00052"></a>00052 
<a name="l00053"></a>00053   <a class="code" href="classDataSet.html" title="a class to store multi-dimensional data">DataSet</a> <a class="code" href="classDataSet.html#a1a27ec9e7f2b521be5175aa4973b6adc">GenerateDataSet</a>() <span class="keyword">const</span>;
<a name="l00056"></a>00056 
<a name="l00057"></a>00057   <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#ac7764490ed2b275d3720e30996869188">kernel_smoothing_factor</a>;
<a name="l00062"></a>00062 
<a name="l00063"></a><a class="code" href="classDataSet.html#abf221c899e73e154ff9cb611380b3feb">00063</a>   <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classDataSet.html#abf221c899e73e154ff9cb611380b3feb" title="function to set a fixed random seed">SetRandomSeed</a>(<span class="keywordtype">int</span> seed)
<a name="l00064"></a>00064   {
<a name="l00065"></a>00065     <a class="code" href="classDataSet.html#ab6b2ba7b0adca376ba99086a021ef884" title="random number generator">irand</a>.seed(seed);
<a name="l00066"></a>00066   }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069   <span class="keyword">friend</span> ostream&amp; <a class="code" href="classDataSet.html#a2979dd04560882ed9e4533ccea473bc6" title="streaming operator for debugging purposes">operator&lt;&lt;</a>(ostream&amp; os, <span class="keyword">const</span> <a class="code" href="classDataSet.html" title="a class to store multi-dimensional data">DataSet</a>&amp;);
<a name="l00071"></a>00071 
<a name="l00072"></a>00072   valarray&lt;double&gt; <a class="code" href="classDataSet.html#ae505190ff2d4218019bce303108192e6" title="vector to store width info">one_over_width</a>;
<a name="l00074"></a>00074 
<a name="l00075"></a>00075   valarray&lt;double&gt; <a class="code" href="classDataSet.html#a37bb049ee945bdc4344bd7015f2b9a23" title="vector to store width info">width</a>;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078   valarray&lt;double&gt; <a class="code" href="classDataSet.html#a6f3d9efb73b7351d519cc58e6f889695" title="vector to store min values">min</a>;
<a name="l00080"></a>00080 
<a name="l00081"></a>00081   valarray&lt;double&gt; <a class="code" href="classDataSet.html#ad1091c9131411b8e99a1f2a52faf85be" title="vector to store max values">max</a>;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084   valarray&lt;int&gt; <a class="code" href="classDataSet.html#ab20896c8244623369c67b38ad4e81a5b" title="vector to store number of bins">nbins</a>;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087   valarray&lt;double&gt; <a class="code" href="classDataSet.html#adfab405eda8e41df01199ee4c87d72a2" title="vector to store precision of variables">precision</a>;
<a name="l00089"></a>00089 
<a name="l00090"></a>00090   <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classDataSet.html#a27e878e4de2c6f9d55f340b95dbdf6c3" title="setting to enable bias only in computation of PDF">b_bias_only</a>;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093  <span class="keyword">private</span>:
<a name="l00094"></a>00094   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> <a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>;
<a name="l00096"></a>00096 
<a name="l00097"></a>00097   <a class="code" href="classTensor.html">Tensor&lt;double&gt;</a> <a class="code" href="classDataSet.html#a810993e4426dea4919dc1919b3ea6318">data2</a>;
<a name="l00100"></a>00100   
<a name="l00101"></a>00101   <a class="code" href="classCovariance.html" title="class for Covariance matrix">Covariance</a> <a class="code" href="classDataSet.html#a34fef970d339fe128f40410d8b856106">co</a>;
<a name="l00104"></a>00104 
<a name="l00105"></a>00105   <span class="keywordtype">void</span> <a class="code" href="classDataSet.html#a92bf605df08a3cdb311f0e9c64adb409">Initialize</a>(<span class="keywordtype">int</span> nvar, <span class="keyword">const</span> <span class="keywordtype">double</span>* min, <span class="keyword">const</span> <span class="keywordtype">double</span>* max, 
<a name="l00106"></a>00106                   <span class="keyword">const</span> <span class="keywordtype">double</span>* precision_=NULL);
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   <span class="keyword">static</span> MTRand_int32 <a class="code" href="classDataSet.html#ab6b2ba7b0adca376ba99086a021ef884" title="random number generator">irand</a>;
<a name="l00113"></a>00113 
<a name="l00114"></a>00114   <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classDataSet.html#acc9f560353759821e03b698ec9b707d9" title="boolean to keep track of Gaussian random variables">b_random_gaus</a>;
<a name="l00116"></a>00116 
<a name="l00117"></a>00117   <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#abdb32000d02c4b081b11fa3923e2d641">next_gaus</a>;
<a name="l00120"></a>00120 
<a name="l00121"></a><a class="code" href="classDataSet.html#aff0fae83177a8189dbfaee8fd3980fd5">00121</a>   <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#aff0fae83177a8189dbfaee8fd3980fd5" title="output a normally distributed random variable">Random_Gaus</a>()
<a name="l00122"></a>00122   {
<a name="l00123"></a>00123     <span class="comment">//we&#39;ve already generated another random number</span>
<a name="l00124"></a>00124     <span class="keywordflow">if</span>(<a class="code" href="classDataSet.html#acc9f560353759821e03b698ec9b707d9" title="boolean to keep track of Gaussian random variables">b_random_gaus</a>)
<a name="l00125"></a>00125       {
<a name="l00126"></a>00126         <a class="code" href="classDataSet.html#acc9f560353759821e03b698ec9b707d9" title="boolean to keep track of Gaussian random variables">b_random_gaus</a>=<span class="keyword">false</span>;
<a name="l00127"></a>00127         <span class="keywordflow">return</span> <a class="code" href="classDataSet.html#abdb32000d02c4b081b11fa3923e2d641">next_gaus</a>;
<a name="l00128"></a>00128       }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130     <span class="comment">//else generate two new normal random number</span>
<a name="l00131"></a>00131     <a class="code" href="classDataSet.html#acc9f560353759821e03b698ec9b707d9" title="boolean to keep track of Gaussian random variables">b_random_gaus</a>=<span class="keyword">true</span>;
<a name="l00132"></a>00132     
<a name="l00133"></a>00133     <span class="keywordtype">double</span> s,u,v;
<a name="l00134"></a>00134     <span class="keywordtype">double</span> num1=0;
<a name="l00135"></a>00135     <span class="keywordtype">double</span> num2=0;
<a name="l00136"></a>00136 
<a name="l00137"></a>00137     <span class="keywordflow">while</span>(<span class="keyword">true</span>)
<a name="l00138"></a>00138       {
<a name="l00139"></a>00139         u=<a class="code" href="classDataSet.html#ab6b2ba7b0adca376ba99086a021ef884" title="random number generator">irand</a>.rand_double();
<a name="l00140"></a>00140         v=<a class="code" href="classDataSet.html#ab6b2ba7b0adca376ba99086a021ef884" title="random number generator">irand</a>.rand_double();
<a name="l00141"></a>00141         
<a name="l00142"></a>00142         s=u*u+v*v;
<a name="l00143"></a>00143         
<a name="l00144"></a>00144         <span class="keywordflow">if</span>(s&lt;1.0)
<a name="l00145"></a>00145           {
<a name="l00146"></a>00146             <span class="comment">//num1=num2=0</span>
<a name="l00147"></a>00147             <span class="keywordflow">if</span>(s&gt;0)
<a name="l00148"></a>00148               {
<a name="l00149"></a>00149                 <span class="keywordtype">double</span> part=sqrt(-2*log(s)/s);
<a name="l00150"></a>00150                 num1=u*part;
<a name="l00151"></a>00151                 num2=v*part;
<a name="l00152"></a>00152               }
<a name="l00153"></a>00153             <span class="keywordflow">break</span>;
<a name="l00154"></a>00154           }
<a name="l00155"></a>00155       }
<a name="l00156"></a>00156     
<a name="l00157"></a>00157     <span class="comment">//num1 and num2 are independ normally distribution random number</span>
<a name="l00158"></a>00158     <a class="code" href="classDataSet.html#abdb32000d02c4b081b11fa3923e2d641">next_gaus</a>=num2;
<a name="l00159"></a>00159     <span class="keywordflow">return</span> num1;      
<a name="l00160"></a>00160   }
<a name="l00162"></a>00162 
<a name="l00163"></a>00163   
<a name="l00164"></a><a class="code" href="classDataSet.html#ab46ba586ad86490f9b3dce2067ccc157">00164</a>   <span class="keyword">static</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#ab46ba586ad86490f9b3dce2067ccc157">Random_Poisson</a>(<span class="keywordtype">double</span> lambda)
<a name="l00165"></a>00165   {
<a name="l00166"></a>00166     <span class="keywordflow">if</span>(lambda &gt; 20)
<a name="l00167"></a>00167       {
<a name="l00168"></a>00168         <span class="keywordtype">double</span> result=-1;
<a name="l00169"></a>00169         <span class="keywordtype">double</span> mean=lambda;
<a name="l00170"></a>00170         <span class="keywordtype">double</span> var=sqrt(lambda);
<a name="l00171"></a>00171         
<a name="l00172"></a>00172         <span class="comment">//make sure things are non-negative</span>
<a name="l00173"></a>00173         <span class="keywordflow">while</span>(result&lt;0)
<a name="l00174"></a>00174           {
<a name="l00175"></a>00175             result= <a class="code" href="classDataSet.html#aff0fae83177a8189dbfaee8fd3980fd5" title="output a normally distributed random variable">Random_Gaus</a>()*var + mean;
<a name="l00176"></a>00176           }
<a name="l00177"></a>00177         <span class="keywordflow">return</span> result;
<a name="l00178"></a>00178       }
<a name="l00179"></a>00179 
<a name="l00180"></a>00180     <span class="comment">//if lambda is small, do poisson</span>
<a name="l00181"></a>00181     <span class="comment">//by counting in second, how many decays are in</span>
<a name="l00182"></a>00182     <span class="keywordtype">double</span> time=0;
<a name="l00183"></a>00183     <span class="keywordtype">int</span> count=0;
<a name="l00184"></a>00184     <span class="keywordflow">while</span>(time&lt;lambda)
<a name="l00185"></a>00185       {
<a name="l00186"></a>00186         <span class="comment">//generate an Exponential number</span>
<a name="l00187"></a>00187         <span class="keywordtype">double</span> random=<a class="code" href="classDataSet.html#ab6b2ba7b0adca376ba99086a021ef884" title="random number generator">irand</a>.rand_double();
<a name="l00188"></a>00188         <span class="keywordflow">if</span>(random==1.0) <span class="keywordflow">continue</span>;
<a name="l00189"></a>00189         time+= -log(1-random);
<a name="l00190"></a>00190         <span class="keywordflow">if</span>(time &lt; lambda)
<a name="l00191"></a>00191           count++;
<a name="l00192"></a>00192       }
<a name="l00193"></a>00193     <span class="keywordflow">return</span> count;
<a name="l00194"></a>00194   }
<a name="l00197"></a>00197   <span class="comment">//(non-integer and non-negative)</span>
<a name="l00198"></a>00198 
<a name="l00199"></a>00199   <span class="comment">//private inline functions</span>
<a name="l00200"></a>00200   <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3" title="compute value centered at bin (a particular dimension)">GetBinCenter</a>(<span class="keywordtype">int</span> index, <span class="keywordtype">int</span> bin) <span class="keyword">const</span>;
<a name="l00202"></a>00202   
<a name="l00203"></a>00203   <span class="keyword">inline</span> valarray&lt;double&gt; <a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3" title="compute value centered at bin (a particular dimension)">GetBinCenter</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index) <span class="keyword">const</span>;
<a name="l00206"></a>00206 
<a name="l00207"></a>00207   <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classDataSet.html#aa7f019bcf5bb4fd63238bf8935cd306a">GetBin_helper</a>(<span class="keywordtype">double</span> ntuple, <span class="keywordtype">int</span> bin) <span class="keyword">const</span>;
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 };
<a name="l00213"></a>00213 
<a name="l00214"></a>00214 
<a name="l00215"></a><a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3">00215</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3" title="compute value centered at bin (a particular dimension)">DataSet::GetBinCenter</a>(<span class="keywordtype">int</span> index, <span class="keywordtype">int</span> bin)<span class="keyword"> const</span>
<a name="l00216"></a>00216 <span class="keyword"></span>{
<a name="l00217"></a>00217   <span class="comment">//DEBUG</span>
<a name="l00218"></a>00218   <span class="comment">/*</span>
<a name="l00219"></a>00219 <span class="comment">  cout&lt;&lt;&quot;GetBin small input : &quot;&lt;&lt;index&lt;&lt;&quot;,&quot;&lt;&lt;bin&lt;&lt;endl;</span>
<a name="l00220"></a>00220 <span class="comment">  cout&lt;&lt;&quot;GetBin small output : &quot;&lt;&lt;(index+0.5)*(max[bin]-min[bin])&lt;&lt;&quot;,&quot;&lt;&lt;min[bin]&lt;&lt;endl;</span>
<a name="l00221"></a>00221 <span class="comment">  */</span>
<a name="l00222"></a>00222 
<a name="l00223"></a>00223   <span class="keywordflow">return</span> (index+0.5)*<a class="code" href="classDataSet.html#a37bb049ee945bdc4344bd7015f2b9a23" title="vector to store width info">width</a>[bin]+<a class="code" href="classDataSet.html#a6f3d9efb73b7351d519cc58e6f889695" title="vector to store min values">min</a>[bin];
<a name="l00224"></a>00224 }
<a name="l00225"></a>00225 
<a name="l00226"></a><a class="code" href="classDataSet.html#a30709a7071a755414f828304ca0b3133">00226</a> <span class="keyword">inline</span> valarray&lt;double&gt; <a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3" title="compute value centered at bin (a particular dimension)">DataSet::GetBinCenter</a>(<span class="keyword">const</span> valarray&lt;int&gt;&amp; index)<span class="keyword"> const</span>
<a name="l00227"></a>00227 <span class="keyword"></span>{
<a name="l00228"></a>00228   assert(index.size()==<a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>);
<a name="l00229"></a>00229   valarray&lt;double&gt; result(<a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>);
<a name="l00230"></a>00230   
<a name="l00231"></a>00231   <span class="comment">//grab central value of bin in each dimension</span>
<a name="l00232"></a>00232   <span class="keywordflow">for</span>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;result.size(); i++)
<a name="l00233"></a>00233     {
<a name="l00234"></a>00234       result[i]=<a class="code" href="classDataSet.html#ae5631df5826534bb6488e3170ba0d1d3" title="compute value centered at bin (a particular dimension)">GetBinCenter</a>(index[i], i);
<a name="l00235"></a>00235     }
<a name="l00236"></a>00236 
<a name="l00237"></a>00237   <span class="keywordflow">return</span> result;
<a name="l00238"></a>00238 }
<a name="l00239"></a>00239 
<a name="l00240"></a><a class="code" href="classDataSet.html#aa7f019bcf5bb4fd63238bf8935cd306a">00240</a> <span class="keyword">inline</span> <span class="keywordtype">int</span> <a class="code" href="classDataSet.html#aa7f019bcf5bb4fd63238bf8935cd306a">DataSet::GetBin_helper</a>(<span class="keywordtype">double</span> value, <span class="keywordtype">int</span> bin)<span class="keyword"> const</span>
<a name="l00241"></a>00241 <span class="keyword"></span>{
<a name="l00242"></a>00242   <span class="keywordtype">double</span> temp_bin= (value-<a class="code" href="classDataSet.html#a6f3d9efb73b7351d519cc58e6f889695" title="vector to store min values">min</a>[bin])*<a class="code" href="classDataSet.html#ae505190ff2d4218019bce303108192e6" title="vector to store width info">one_over_width</a>[bin];
<a name="l00243"></a>00243   <span class="comment">//if value is in underflowed, go to the zeroth bin</span>
<a name="l00244"></a>00244   <span class="keywordflow">if</span>(temp_bin&lt;0) <span class="keywordflow">return</span> 0;
<a name="l00245"></a>00245   
<a name="l00246"></a>00246   <span class="comment">//if value is overflowed, go to the last bin</span>
<a name="l00247"></a>00247   <span class="keywordflow">if</span>(temp_bin&gt;=<a class="code" href="classDataSet.html#ab20896c8244623369c67b38ad4e81a5b" title="vector to store number of bins">nbins</a>[bin]) <span class="keywordflow">return</span> <a class="code" href="classDataSet.html#ab20896c8244623369c67b38ad4e81a5b" title="vector to store number of bins">nbins</a>[bin]-1;
<a name="l00248"></a>00248   <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(temp_bin);
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 
<a name="l00251"></a><a class="code" href="classDataSet.html#a7261bb29701a071f76349854d1f39cb0">00251</a> <span class="keyword">inline</span> valarray&lt;int&gt; <a class="code" href="classDataSet.html#a7261bb29701a071f76349854d1f39cb0">DataSet::GetBin</a>(<span class="keyword">const</span> valarray&lt;double&gt;&amp; ntuple)<span class="keyword"> const</span>
<a name="l00252"></a>00252 <span class="keyword"></span>{
<a name="l00253"></a>00253   assert(ntuple.size()==<a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>);
<a name="l00254"></a>00254   valarray&lt;int&gt; result_bin(<a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>);
<a name="l00255"></a>00255   
<a name="l00256"></a>00256   <span class="comment">//convert multimensional bin to 1D binning</span>
<a name="l00257"></a>00257   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classDataSet.html#a4a82950e47b524eb2e242e00e17eb2d4" title="to store multidimensional info">data</a>.<a class="code" href="classTensor.html#abf6ecd9801e5de52c9e5255cbb4d1604" title="rank/dimension of tensor">rank</a>; i++)
<a name="l00258"></a>00258     {
<a name="l00259"></a>00259       result_bin[i]=<a class="code" href="classDataSet.html#aa7f019bcf5bb4fd63238bf8935cd306a">GetBin_helper</a>(ntuple[i], i);
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261   <span class="keywordflow">return</span> result_bin;
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263 
<a name="l00264"></a>00264 
<a name="l00265"></a>00265 <span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Sep 12 2013 17:12:58 for Data Driven Substructure by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
